<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="robots" content="noindex" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>微信支付</title>
  </head>
  <body>
    <h1 id="msgTip">正在前往微信支付，请耐心等待。</h1>
    <script>
      const searchParams = new URLSearchParams(location.search)
      const orderId = searchParams.get('orderId')
      const price = searchParams.get('price')
      fetch('https://pubg.bittopup.com/api/orderId2WXUrl', {
        method: 'POST', // 指定请求方法为POST
        headers: {
          'Content-Type': 'application/json', // 指定发送的数据类型为JSON
        },
        body: JSON.stringify({
          orderId: orderId, // 将数据转为JSON字符串
        }),
      })
        .then(async function (response) {
          const { data } = await response.json() // 解析JSON响应
          if (!data) throw new Error('无地址')
          location.href = `https://pay.bittopup.com/?url=${encodeURIComponent(data)}&price=${price}`
        })
        .catch((e) => {
          document.getElementById('msgTip').style.display = 'block'
          document.getElementById('msgTip').innerText = '拉起微信支付失败，请返回重新下单，多次失败请联系客服'
        })
    </script>
  </body>
</html>
